<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mockery\Exception;

/**
 * App\PrizeRecords
 *
 * @mixin \Eloquent
 */
class PrizeRecords extends Model
{
    protected $table = "prize_records";
    public $timestamps = false;


    //订单状态
    const STATUS_WAITTING = 0;
    const STATUS_PENDING = 1;
    const STATUS_AGREE = 2;
    const STATUS_REFUSE = 3;

    static $StatusDisplay = [
        self::STATUS_WAITTING => '待用户确认',
        self::STATUS_PENDING => '待处理',
        self::STATUS_AGREE => '已通过',
        self::STATUS_REFUSE => '已拒绝',
    ];


    //奖品类型
    const TYPE_NONE = 0;
    const TYPE_REAL = 1;
    const TYPE_COIN = 2;
    const TYPE_CHARGE = 3;

    static $TypeDisplay = [
        self::TYPE_NONE => '谢谢惠顾',
        self::TYPE_REAL => '实物',
        self::TYPE_COIN => '金币',
        self::TYPE_CHARGE => '虚拟物品',
    ];


    /**
     * 拒绝
     * @param $prizeRecords
     * @param $request
     * @return array
     */
    static function Refuse($prizeRecords, $request)
    {
        try {
            $prizeRecords->status = self::STATUS_REFUSE;
            $prizeRecords->check_content = $request->check_content;
            if (!$prizeRecords->save()) {
                return ['status' => 2, 'message' => '失败'];
            }
            return ['status' => 1, 'message' => '成功'];
        } catch (Exception $exception) {
            return ['status' => 2, 'message' => '失败'];
        }
    }


    /**
     * 通过
     * @param $prizeRecords
     * @param $request
     * @return array
     */
    static function Agree($prizeRecords, $request)
    {
        try {
            $prizeRecords->status = self::STATUS_AGREE;
            $prizeRecords->express_name = $request->express_name;
            $prizeRecords->express_order = $request->express_order;
            if (!$prizeRecords->save()) {
                return ['status' => 2, 'message' => '失败'];
            }
            return ['status' => 1, 'message' => '成功'];
        } catch (Exception $exception) {
            return ['status' => 2, 'message' => '失败'];
        }
    }
}
